package cn.fenglaicaimi.base.service.impl;

import cn.fenglaicaimi.base.domain.Good;
import cn.fenglaicaimi.base.mapper.GoodMapper;
import cn.fenglaicaimi.base.qo.GoodQuery;
import cn.fenglaicaimi.base.service.IGoodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service@Transactional
public class GoodServiceImpl implements IGoodService {
    @Autowired
    private GoodMapper goodMapper;


    @Override
    public int save(Good good) {
        return this.goodMapper.insert(good);
    }

    @Override
    public int delete(Long id) {
        return this.goodMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(Good good) {
        return this.goodMapper.updateByPrimaryKey(good);
    }

    @Override
    public PageInfo query(GoodQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Good> list = this.goodMapper.query(qo);
        return new PageInfo(list);
    }
}
